
import { createApp, App, ComponentPublicInstance } from 'vue'
import MoadlComponent from './Modal.vue'

let instance: App<Element>
let vm: ComponentPublicInstance<Record<string, any>, {}, {}, {}, Record<string, any>>

//创建弹窗
const ModalFunc: CustomTypeModal.ModalConstructor = function (options) {
  instance = createApp(MoadlComponent, {
    ...options
  })
  const el = document.createElement('div')
  el.setAttribute('id', 'modal_content')
  document.body.appendChild(el)
  vm = instance.mount("#modal_content")
}

//关闭弹窗
ModalFunc.close = () => {
  vm.close()
}

//打开弹窗
ModalFunc.show = (options) => {
  if (typeof options === 'string') {
    options = {
      content: options
    }
  }
  ModalFunc({
    ...options,
    value: true
  })
}

export default ModalFunc